﻿using System;
using System.Collections.Generic;
using System.Text;
using Android.App;
using Android.Content;
using Android.Util;
using Com.Baidu.Mapapi;

namespace BaiduMapDemo
{
    [Application]
    public class GlobalApp : Application
    {
        private  BMapManager _baiduMapManager;
        public BMapManager BaiduMapManager
        {
            get
            {
                return _baiduMapManager;
            }
        }

          public static GlobalApp Current;
          public GlobalApp(IntPtr handle, global::Android.Runtime.JniHandleOwnership transfer)
            : base(handle, transfer)
        {
            Current = this;
        }

        public override void OnCreate()
        {
            Log.Debug(this.GetType().ToString(), "Application is Starting....");
            base.OnCreate();
             InitBaiduMapManager(this.ApplicationContext);
           

        }

        public void InitBaiduMapManager(Context context)
        {

            if (_baiduMapManager == null)
            {
                _baiduMapManager = new BMapManager(context);

                //必须在SetContentView之前初始化 BMapManager,否则崩溃.
                //Map API Key  46B2B5299E88C16B30E8B5D06C23BE08098D61E0   from baidu app :跑我
                if (!_baiduMapManager.Init("46B2B5299E88C16B30E8B5D06C23BE08098D61E0", null))
                {
                    Log.Debug("GApplication: ", "BaiduManager初始化失败");
                }
            }

        }
    }
}
